package com.czy.contorller.user;

import com.czy.dto.AddBorrowRecordDto;
import com.czy.dto.UserBorrowPageDto;
import com.czy.result.Result;
import com.czy.service.BorrowRecordService;
import com.czy.vo.PageVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user/borrow")
public class BorrowRecordController {

    @Autowired
    private BorrowRecordService borrowRecordService;

    // 分页查询用户借用资产记录
    @GetMapping("/list")
    public Result<PageVo> list(UserBorrowPageDto userBorrowPageDto) {
        log.info("接收到的借出资产分页数据：{}", userBorrowPageDto);

        PageVo vo = borrowRecordService.list(userBorrowPageDto);

        return Result.success(vo);
    }

    //归还资产
    @PutMapping("/return/{id}")
    public Result returnAsset(@PathVariable Integer id){
        log.info("归还资产的id：{}" ,id);
        borrowRecordService.repaid(id);
        return  Result.success();
    }

    //借出资产
   @PostMapping("/apply")
    public Result borrowAsset(@RequestBody AddBorrowRecordDto addBorrowRecordDto){
        log.info("借出资产的数据：{}", addBorrowRecordDto);
        borrowRecordService.addBorrowRecord(addBorrowRecordDto);
        return Result.success();
   }
}
